import { http } from "@/utils/http";

/**
 * 交易贷款客户信息接口
 */
export interface TradeCustomer {
  id: number;
  name: string; // 客户名称
  borrower_name: string; // 基本信息
  phone: string; // 手机号码
  id_card_front: string; // 证件资料
  loan_amount: number; // 放款金额
  status: number; // 状态
  customer_type: number; // 客户类型
  loan_time: string; // 贷款时间
  created_at: string;
  updated_at: string;
  [key: string]: any; // 其他可能的字段
}

/**
 * 交易贷款客户列表响应接口
 */
export interface TradeCustomerListResponse {
  code: number;
  data: {
    list: TradeCustomer[];
    total: number;
    total_pages: number;
  };
  error: number;
  msg: string;
  success: boolean;
}

/**
 * 交易贷款客户详情响应接口
 */
export interface TradeCustomerDetailResponse {
  code: number;
  data: {
    customer: TradeCustomer;
    payment_channels?: Array<{
      channel: string;
      amount: number;
      expected_time: string;
      [key: string]: any;
    }>;
    [key: string]: any;
  };
  error: number;
  msg: string;
  success: boolean;
}

/**
 * 获取交易贷款客户列表
 * @param params 
 * @returns 
 */
export const getTradeCustomerList = (params: {
  name?: string;
  phone?: string;
  id_number?: string;
  partner_id?: number;
  manager_id?: number;
  page?: number;
  page_size?: number;
}) => {
  return http.request<TradeCustomerListResponse>(
    "post",
    "/investor/trade-customer/list",
    { data: params }
  );
};

/**
 * 获取交易贷款客户详情
 * @param id 客户ID
 * @returns 
 */
export const getTradeCustomerDetail = (id: string | number) => {
  // 确保 id 是整数
  const numericId = typeof id === 'string' ? parseInt(id) : id;

  return http.request<TradeCustomerDetailResponse>(
    "post",
    "/investor/trade-customer/detail",
    { data: { id: numericId } }
  );
}; 